
#ifndef __RSA_SIGNING_H
#define __RSA_SIGNING_H

#include "CryptoPipeBlock.h"
#include "../aprtools/APRBucketBrigade.h"
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include "RSAPrivateKey.h"

/** Class encapsulating an interface to signing with an RSA private
 * key. */
class RSASigning : public CryptoPipeBlock
{
   public:
      RSASigning(const RSAPrivateKey &rsaprvkey);
      RSASigning(APRBucketBrigade &iinput, APRBucketBrigade &ioutput, const RSAPrivateKey &rsaprvkey);
      ~RSASigning();
      // Sign data block and return signed data block
      char *processDataBlock(const char *datablock, apr_size_t datasize, apr_size_t *signedsize);
      // Begin signing of the data pipe
      int processPipeBegin();
      // Step through the signing of the data pipe
      int processPipeStep();
      // Step through the data, recording data movement
      int processPipeStep(int *movementin, int *movementout);
      // End signing of the data pipe
      int processPipeEnd();
      /** Was the process secure? */
      int processWasSecure() { return 1; }
   private:
      /** A copy of the RSA private key. */
      RSA *key;
      /** The input bucket brigade. As this is pointer to the outside,
       * it is not deleted in the destructor. */
      APRBucketBrigade *input;
      /** The output bucket brigade. As this is pointer to the
       * outside, it is not deleted in the destructor. */
      APRBucketBrigade *output;
      /** The message digest context which holds the state of the
       * digest. */
      EVP_MD_CTX e_ctxt;
};

#endif
